package com.sy.controller;

import com.sy.service.PhoneService;
import com.sy.utils.ResultVOUtil;
import com.sy.vo.DataVO;
import com.sy.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by 时宇 on 2021-08-06 16:33
 */
@RestController
@RequestMapping("/phone")
@Slf4j
@CrossOrigin
public class PhoneHandler {
    @Resource
    private PhoneService phoneService;

    @GetMapping("/index")
    public ResultVO index(){
        DataVO dataVO = phoneService.findDataVO();
        return ResultVOUtil.success(dataVO);
    }

    @GetMapping("/findByCategoryType/{categoryType}")
    public ResultVO findByCategoryType(
            @PathVariable("categoryType") Integer categoryType ){
        return ResultVOUtil.success(phoneService.findPhoneInfoVOByCategoryType(categoryType));
    }

    @GetMapping("/findSpecsByPhoneId/{phoneId}")
    public ResultVO findSpecsByPhoneId(
            @PathVariable("phoneId") Integer phoneId){

        return ResultVOUtil.success(phoneService.findSpecsByPhoneId(phoneId));
    }
}
